package com.erytech.linktalk.web.client.datasource;

import java.util.HashMap;

import com.erytech.linktalk.web.client.framework.DataSource;
import com.google.gwt.user.client.ui.Image;

public class PortraitDataSource extends DataSource {
	
	static final int ROW_COUNT = 10;
	static final int COL_COUNT = 10;
	
	HashMap portraitMap = new HashMap(101);
	
	int selected = 1;
	
	public PortraitDataSource() {
		int count = ROW_COUNT * COL_COUNT;
		for (int i = 1; i <=count; i++) {
			portraitMap.put("" + i, new Image(getPortraitSrc("" + i)));
		}
	}
	
	public int getRowCount() {
		return ROW_COUNT;
	}

	public int getColCount() {
		return COL_COUNT;
	}
	
	public String getSelected() {
		return "" + selected;
	}
	
	public void setSelected(int row, int col) {
		selected = getPortraitIndex(row, col);
		fireDataUpdateEvent(new PortraintChangeListener(this));
	}

	public String getPortraitSrc(String index) {
		return "icons/qq_" + index + ".png";
	}

	public Image getPortraint(int row, int col) {
		return (Image)portraitMap.get("" + getPortraitIndex(row, col));
	}

	public int getPortraitIndex(int row, int col) {
		return row * 10 + col + 1;
	}

	public Image getSelectedPortrait() {
		return (Image)portraitMap.get(getSelected());
	}

}
